package com.framework.modules.appindex;

import com.framework.entity.or.OrAppMenu;
import com.framework.entity.or.OrAppMenuType;
import com.framework.exception.util.RespResult;
import com.framework.modules.sys.controller.AbstractController;
import com.framework.page.PageUtils;
import com.framework.service.AppMenuService;
import com.framework.service.app.OrAppMenuTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * app首页轮播图按钮相关
 * @author wq
 */
@RestController
@RequestMapping("/sys/appMenu")
public class appMenuController extends  AbstractController{

    @Autowired
    private AppMenuService appMenuService;

    @Autowired
    private OrAppMenuTypeService orAppMenuTypeService;

    /**
     * 轮播图列表
     * @param params
     * @return
     */
    @RequestMapping("/list")
    public RespResult queryBannerList(@RequestParam Map<String,Object> params){
        params.put("deptId",getUser().getDeptId());
        PageUtils page =appMenuService.queryAppMenuListForAdmin(params);
        return RespResult.ok().put("page",page);
    }

    /**
     * 通过id查询
     * @param menuId
     * @return
     */
    @RequestMapping("/queryById/{menuId}")
    public RespResult queryOrAppMenu(@PathVariable Long menuId){
        OrAppMenu appMenu = appMenuService.selectById(menuId);
        return RespResult.ok().put("appMenu",appMenu);
    }

    /**
     * 修改
     * @param orAppMenu
     * @return
     */
    @RequestMapping("/update")
    public RespResult update(@RequestBody OrAppMenu orAppMenu){
        appMenuService.updateMenuById(orAppMenu);
        return RespResult.ok();
    }

    @RequestMapping("getMenuType")
    public RespResult getMenuType(){
        List<OrAppMenuType> list=orAppMenuTypeService.queryMenuType(getDeptId());
        return RespResult.ok().put("types",list);
    }

}
